﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TB.DataModel.DTO;
using TB.DAL;

namespace TB.BLL
{
    public class MessageHandler
    {

        //public static MessageHandler Instance = Instance = new MessageHandler();
        public DbHandler DbHandler { get; set; }
          
        
        public MessageHandler()
        {
            DbHandler = new DbHandler();
        }

        public bool SaveMessage(Message msg)
        {
            DbHandler.SaveMessageToDb(msg);
            return true;
        }


        public IList<Message> GetAllMessages()
        {
            return DbHandler.GetMessageBetweenDatesFromDb(DateTime.Now.AddDays(-3),DateTime.Now);            
        }

        public IList<Message> ShufelMessages(IList<Message> msgs)
        {
            Message tmp;
            int randPos;
            Random rand = new Random();
            for (int i = 0; i < msgs.Count; i++)
            {
                tmp = msgs[i];
                randPos = rand.Next(i, msgs.Count-1);
                msgs[i] = msgs[randPos];
                msgs[randPos] = tmp;
            }
            return msgs;
        }
    }
}
